package com.cleaningcloud.cld.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cleaningcloud.common.core.utils.DateUtils;
import com.cleaningcloud.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.domain.CldInvoiceDeduction;
import com.cleaningcloud.cld.service.ICldInvoiceDeductionService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 发票扣款Controller
 * 
 * @author cleaningcloud
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/invoiceDeduction")
public class CldInvoiceDeductionController extends BaseController
{
    @Autowired
    private ICldInvoiceDeductionService cldInvoiceDeductionService;

    /**
     * 查询发票扣款列表
     */
    @RequiresPermissions("cld:invoiceDeduction:list")
    @GetMapping("/list")
    public TableDataInfo list(CldInvoiceDeduction cldInvoiceDeduction)
    {
        startPage();
        List<CldInvoiceDeduction> list = cldInvoiceDeductionService.selectCldInvoiceDeductionList(cldInvoiceDeduction);
        return getDataTable(list);
    }

    /**
     * 导出发票扣款列表
     */
    @RequiresPermissions("cld:invoiceDeduction:export")
    @Log(title = "发票扣款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CldInvoiceDeduction cldInvoiceDeduction)
    {
        List<CldInvoiceDeduction> list = cldInvoiceDeductionService.selectCldInvoiceDeductionList(cldInvoiceDeduction);
        ExcelUtil<CldInvoiceDeduction> util = new ExcelUtil<CldInvoiceDeduction>(CldInvoiceDeduction.class);
        util.exportExcel(response, list, "发票扣款数据");
    }

    /**
     * 获取发票扣款详细信息
     */
    @RequiresPermissions("cld:invoiceDeduction:query")
    @GetMapping(value = "/{invoiceDeductionId}")
    public AjaxResult getInfo(@PathVariable("invoiceDeductionId") Long invoiceDeductionId)
    {
        return success(cldInvoiceDeductionService.selectCldInvoiceDeductionByInvoiceDeductionId(invoiceDeductionId));
    }

    /**
     * 新增发票扣款
     */
    @RequiresPermissions("cld:invoiceDeduction:add")
    @Log(title = "发票扣款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldInvoiceDeduction cldInvoiceDeduction)
    {
        return toAjax(cldInvoiceDeductionService.insertCldInvoiceDeduction(cldInvoiceDeduction));
    }

    /**
     * 修改发票扣款
     */
    @RequiresPermissions("cld:invoiceDeduction:edit")
    @Log(title = "发票扣款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldInvoiceDeduction cldInvoiceDeduction)
    {
        return toAjax(cldInvoiceDeductionService.updateCldInvoiceDeduction(cldInvoiceDeduction));
    }

    /**
     * 删除发票扣款
     */
    @RequiresPermissions("cld:invoiceDeduction:remove")
    @Log(title = "发票扣款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{invoiceDeductionIds}")
    public AjaxResult remove(@PathVariable Long[] invoiceDeductionIds)
    {
        return toAjax(cldInvoiceDeductionService.deleteCldInvoiceDeductionByInvoiceDeductionIds(invoiceDeductionIds));
    }
}
